﻿@{
   
}
@section head{
    <link href="@Url.Content("~/Js/Validform_v5.3.2/css/style.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Js/Validform_v5.3.2/js/Validform_v5.3.2_min.js")" type="text/javascript"></script>
}
<form id="form1" action="@Url.Action("IndustrySave")" method="post" name="form1">
<div class="rightbar">
    <p class="righttit">
        <span id="updateTitle">添加信息</span></p>
    <div class="rightshow">
        <table width="80%" border="0" cellspacing="0" cellpadding="0" class="m20">
            <tr>
                <th width="7%" height="34" align="right">
                    <p>
                        分类名称：</p>
                </th>
                <td colspan="2">
                    <input type="text" class="text" id="IndustryName"  name="IndustryName" value="@Model.IndustryName"/>
                    <span class="Validform_checktip"></span>
                </td>
            </tr>
            <tr>
                <th height="34" align="right" width="9%">
                    <p>
                        所属分类：</p>
                </th>
                <td colspan="2">
                    <select id="ParentId" name="ParentId" style="width: 155px;" class="select">
                        <option level="0" value="0">根分类</option>
                        @helper renderType(string pid)
                            {
                                System.Data.DataView dv = new System.Data.DataView(@ViewBag.Product_IndustryDt);
                                dv.RowFilter = "[parentId]=" + pid;

                                foreach (System.Data.DataRowView drv in dv)
                                {
                                    string id = drv["Id"].ToString();
                                    int level = Common.TypeParse.ObjectToInt(drv["LeveId"], 0);
                                    drv["IndustryName"] = "└" + drv["IndustryName"];
                            <option level="@level" value="@id" @(int.Parse(id) == @Model.ParentId ? "selected" : "")>@MvcHtmlString.Create(@drv["IndustryName"].ToString())</option>
                            @renderType(id);
                                }
                        }
                        @renderType("0")
                    </select>
                </td>
            </tr>
            <tr>
                <td height="60">
                    <input type="hidden" name="Id" value="@Model.Id" id="hiddenId"/>
                    <input type="hidden" name="LeveId" value="@Model.LeveId" id="hiddenLevel"/>
                </td>
                <td width="10%">
                    <a href="###" id="btnSubmit" class="sbtn1"><span class="white">确定</span></a>
                </td>
                <td width="83%">
                    <a href="javascript:history.go(-1);" class="sbtn2"><span class="white">取消</span></a>
                </td>
            </tr>
        </table>
    </div>
</div>
</form>
@section Script{
    <script type="text/javascript">
        $(function () {
            //提交验证
            var formSubmit = $("#form1").Validform({
                btnSubmit: "#btnSubmit",
                tiptype: function (msg, o, cssctl) {
                    //msg：提示信息;
                    //o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
                    //cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
                    if (!o.obj.is("form")) {//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
                        var objtip = o.obj.siblings(".Validform_checktip");
                        cssctl(objtip, o.type);
                        objtip.text(msg);
                    } else {
                        var objtip = o.obj.find("#msgdemo");
                        cssctl(objtip, o.type);
                        objtip.text(msg);
                    }
                },
                ajaxPost: true,
                showAllError: true,
                beforeSubmit: function () {
                    //在验证成功后，表单提交前执行的函数，curform参数是当前表单对象。
                    //这里明确return false的话表单将不会提交;	
                    var level = $("#ParentId option:selected").attr("level");
                    $("#hiddenLevel").val(Number(level) + Number(1));
                },
                callback: function (data) {   //data是object类型
                    if (data == "1") {
                        window.location.href = "/Admin/ProMgr/IndustryList";
                    }
                    else if (data == "0") {
                        art.dialog({
                            title: "提示",
                            icon: "warning",
                            content: "操作失败！",
                            time: 2
                        });
                    }
                }
            }).addRule([{
                ele: "#Name",
                datatype: "s2-18",
                nullmsg: "请输入分类名称！",
                errormsg: "标题至少2个字符,最多18个字符！"
            }]);
        });
    </script>
}
